--- 战策三·李代桃僵
local policy3 = fk.CreateSkill {
    name = "other_replace",
    tags = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

local HG = require "packages.new_heg_diy_my.util"

Fk:loadTranslationTable{
    ["@[other_replace_mark]"] = "李代桃僵",
    ["other_replace_ask"] = "战策-李代桃僵：你可以防止此伤害，然后你摸一张牌且伤害来源对你造成等量伤害",
}

policy3:addEffect(fk.DetermineDamageInflicted, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy3.name .. "_mark"
        return player:getMark(mark_name) ~= 0 and not player.dead and player ~= target and data.damage >= target.hp
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = "unknownpolicy", prompt = "other_replace_ask" })
    end,
    on_use = function(self, event, target, player, data)
        local mark_name = "@[private]" .. self.name .. "_mark"
        local room = player.room
        player:drawCards(1, policy3.name)
        room:damage {
            from = data.from,
            to = player,
            damage = data.damage,
            skillName = policy3.name,
        }
        data:preventDamage()
        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-other_replace", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy3.name })
        local card = Fk:cloneCard("heg_other_replace")
        room:getVirtCardId(card)
        room:showVirtualCard(card, player, nil, room.logic:getCurrentEvent().id + 1)
    end,
})

return policy3
